<?php
	include_once '../include/inc_session.php';
	
	$sEdition =$_GET['edition'];
	$sDateDebut =$_GET['dd'];
	$sDateFin =$_GET['df'];
	
	$oEditions = new dataObject_editions();
	$oElementDico = new dataObject_elementdico();
	
	$sNomModule = $oBloc->_MENU_NOM;
	$sNomListe;
	$bEnvoiMail = false;

	//on envoi le mail si click sur le bouton envoi mail
	if($gbFormValid && isset($_POST['Envoyer']))
	{
		//$sMsgWait = "Veuillez patienter pendant l'envoi du mail... ";
		include_once 'succes_envoi_mail.php';
	}
	if(isset($_POST['Retour'])) header('location:index.php');
	
	$aEnteteTab = array(
	array("num_colonne"=>1, "nom_colonne"=>"Contrat"),
	array("num_colonne"=>2, "nom_colonne"=>"Date effet"),
	array("num_colonne"=>3, "nom_colonne"=>"Offre"),
	array("num_colonne"=>4, "nom_colonne"=>"Produit"),
	array("num_colonne"=>5, "nom_colonne"=>"Formule")
	);

	switch ($sEdition)
	{
		case '134':
				header("Location:echeances.php?edition=$sEdition&dd=$sDateDebut&df=$sDateFin");
				break;
				
		case '135':
				$sNomListe = $oElementDico->elementdico_getNomFromCode(AG,dataObject_dictionnaire::LISTES_EDITION);
				$aEnteteTab = array_merge($aEnteteTab,array(array("num_colonne"=>6, "nom_colonne"=>"Acte de gestion")
				));
				$aPdfWidthRecord_135 = array("Contrat" => 16,
											   "Date effet" => 12,
							"Offre" => 14,
							"Produit" => 16,
							"Formule" => 20,
							"Acte de gestion" => 22
							);
				$sTabActe="<tr id='niv1'>
							<td class='col3' style='width:30%'>&nbsp;</td>
							<td class='col3' style='text-align:center; height:25px; width:30%; font-weight:bold;' >Acte de gestion</td>
							<td class='col2' style='text-align:center; height:25px; width:30%; font-weight:bold;'>Nombre d'actes</td>
							</tr>";
				$aActe = array();
				break;

		case '136':
				header("Location:echeances.php?edition=$sEdition&dd=$sDateDebut&df=$sDateFin");
				break;

		case '137':
				$sNomListe = $oElementDico->elementdico_getNomFromCode('SID',dataObject_dictionnaire::LISTES_EDITION);
				$aEnteteTab = array_merge($aEnteteTab,
				array(array("num_colonne"=>6, "nom_colonne"=>"Type"),
				array("num_colonne"=>7, "nom_colonne"=>"Date <br/>survenance&nbsp;d&eacute;claration"),
				array("num_colonne"=>9, "nom_colonne"=>"Etat"),
				array("num_colonne"=>10, "nom_colonne"=>"D&eacute;cision"),
				array("num_colonne"=>11, "nom_colonne"=>"Motif refus")
				));
				$aPdfWidthRecord_137 = array("Contrat" => 12,
											   "Date effet" => 7,
							"Offre" => 10,
							"Produit" => 10,
							"Formule" => 16,
							"Type" => 7,
							"Date <br/>survenance&nbsp;déclaration" => 14,
							"Etat" => 7,
							"D&eacute;cision" => 7,
							"Motif refus" => 8,
							"Type de sinistre" => 33,
							"Nombre de sinistres" => 33
							);
				$sTabSinistreDec = "
						<tr id='niv1'>
							<td class='col3' style='height:25px; width:34%;'></td>
							<td  class='col3' style='text-align:center; height:25px; width:".$aPdfWidthRecord_137['Type de sinistre']."%; font-weight:bold;' >Type de sinistre</td>
							<td  class='col3' style='text-align:center; height:25px; width:".$aPdfWidthRecord_137['Nombre de sinistres']."%; font-weight:bold;' >Nombre de sinistres</td>
						</tr>";
				$aSinistreDec = array();
				break;

		case '138':
				$sNomListe = $oElementDico->elementdico_getNomFromCode(SIR,dataObject_dictionnaire::LISTES_EDITION);
				$aEnteteTab = array_merge($aEnteteTab,array(array("num_colonne"=>6, "nom_colonne"=>"Type"),
				array("num_colonne"=>7, "nom_colonne"=>"Date <br/>survenance&nbsp;d&eacute;claration"),
				/*array("num_colonne"=>8, "nom_colonne"=>"Date d&eacute;claration"),*/
				array("num_colonne"=>9, "nom_colonne"=>"Type prestation"),
				array("num_colonne"=>10, "nom_colonne"=>"Montant"),
				array("num_colonne"=>11, "nom_colonne"=>"Date r&eacute;glement")
				));
				$aPdfWidthRecord_138 = array("Contrat" => 10,
											   "Date effet" => 8,
							"Offre" => 10,
							"Produit" => 10,
							"Formule" => 14,
							"Type" => 7,
							"Date <br/>survenance&nbsp;déclaration" => 14,
							"Type prestation" => 8,
							"Montant" => 7,
							"Date r&eacute;glement" => 10
							);
				$sTabSinistreReg="
					<tr id='niv1'>
						<td class='col3' style='height:25px; width:20%;'></td>
						<td class='col3' align='center' style='height:25px; width:20%; font-weight:bold;'>Type sinistres</td>
						<td class='col3' align='center' style='height:25px; width:20%; font-weight:bold;'>Nombre sinistres</td>
						<td class='col3' align='center' style='height:25px; width:20%; font-weight:bold;'>Type prestations</td>
						<td class='col2' nowrap='nowrap' align='center' style='height:25px; width:20%; font-weight:bold;'>Montant prestations</td>
					</tr>";
				$aSinistreReg=array();
				$aPrestation=array();
				break;

		case '139':
				$sNomListe = $oElementDico->elementdico_getNomFromCode(SO,dataObject_dictionnaire::LISTES_EDITION);
				$aEnteteTab = array_merge($aEnteteTab,array(array("num_colonne"=>6, "nom_colonne"=>"Cotisation"),
						array("num_colonne"=>7, "nom_colonne"=>"Droit entr&eacute;e"),
						array("num_colonne"=>8, "nom_colonne"=>"Fr&eacute;quence")));
				$aPdfWidthRecord_139 = array("Contrat" => 14,
											   "Date effet" => 10,
							"Offre" => 12,
							"Produit" => 12,
							"Formule" => 18,
							"Cotisation" => 6,
							"Droit entr&eacute;e" => 8,
							"Fr&eacute;quence" => 12
							);
				$sTabSous ="
							<tr id='niv1'>
							<td  class='col5' style='text-align:center;  width:24%; font-weight:bold;'></td>
							<td  class='col5' style='text-align:center;  width:26%; font-weight:bold;'>Nombre Contrats</td>
							<td  class='col5' style='text-align:center;  width:25%; font-weight:bold;'>Montant Cotisations</td>
							<td  class='col5' style='text-align:center;  width:25%; font-weight:bold;'>Montant Droits entr&eacute;e</td>
							</tr>";
				$fTotalCotisation = $iNbContrat = $fTotalDE = 0;
				break;
	}
	$sSepareTable = '</table><div id="br2"></div>
					 <table class="tab_list" border="1" style="width:100%;  border:1px solid black; border-collapse:collapse;">';
	

?>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
	<head>
		<meta http-equiv="Content-Type" content="text/html; charset=UTF-8" />
		<meta http-equiv="X-UA-Compatible" content="IE=8" />
			<title>Editions</title>
			<link rel="stylesheet" type="text/css" href="../css/main_editions.css" />
            <link rel="stylesheet" type="text/css" href="../css/list_editions.css" />
			<!--[if IE 7]>
            	<link rel="stylesheet" type="text/css" href="../css/ie7.css" />
            	<link rel="stylesheet" type="text/css" href="form_ie7.css" />
            <![endif]-->
            <script> 
			function printEdition(urlImpression)
		    {
		    	options = "Width=850,Height=670" ;
		    	window.open(urlImpression,"editions_agent", options) ;
		    }
			</script>
			
	</head>
	<body>
		<div id="sf_menu1">
			<h3><?php echo $sNomModule ?></h3>
			<div id="information_erreur">
			<?php 
				if(isset($sMsgWait)) echo colorer($sMsgWait, "false");
				$aMessages = $oForm->getValidMessage();
				if(!empty($aMessages))
				{
			?>
				<ul id="message">
					<li><?php echo $aMessages[0]['message'] ?></li>
				</ul>
			<?php } ?>
			</div>
		</div><!-- fin sf_menu1 -->
		
		<div class="cleared"></div>
		
		<div class="corps1">
			
		<!--/***************************************/-->
			<div class="imgleft1"></div>
			
				
			<div class="imgmiddle1">
				<div class="btn">
		        	<span class="btnleft"></span>
		            <span class="btnmiddle">
		            	<h5>Demande d'&eacute;dition</h5>
		            </span><span class="btnright"></span>
		        </div>
				<div class="btn1">
		        	<span class="btnleft"></span>
		            <span class="btnmiddle">
		            	<h5>D&eacute;tail &eacute;dition</h5>
		            </span><span class="btnright"></span>
		        </div>
		        <PDF>
				<table align="center">
					<tr>
						<td align="center"><font size="2"><?php echo $sNomListe.'	du	'.formaterDate($sDateDebut,"-","/",false).'	au	'.formaterDate($sDateFin,"-","/",false)?></font></td>
					</tr>
				</table>
				<div id='br2'></div>
<?php
	if (!$bEnvoiMail)
	{
		$aInfosAgent = $oEditions->agentUniteRegion($_SESSION[iduser]);
?>
				<div class="content_table bright">
				<table style="width:100%; text-align:left">
					<tr>
						<td class="gauche">R&eacute;gion : </td>
						<td class="gauche"><?php echo $aInfosAgent['Code_region']?></td>
						<td class="gauche"><?php echo $aInfosAgent['Nom_region']?></td>
					</tr>
					<tr>
						<td class="gauche">Unit&eacute; : </td>
						<td class="gauche"><?php echo $aInfosAgent['Code_unite']?></td>
						<td class="gauche"><?php echo $aInfosAgent['Nom_unite'] ?></td>
					</tr>
					<tr>
						<td class="gauche">Agent : </td>
						<td class="gauche"><?php echo $aInfosAgent['Code_agent'] ?></td>
						<td class="gauche"><?php echo $aInfosAgent['Nom_agent'] ?></td>
					</tr>
				</table>
				<hr width="95%" style=" margin-right:17px; width:838px;"/>
				<div id='cleared'></div>
				<table class="tab_list"  style="width:100%; border:1px solid black; border-collapse:collapse;" border="1" >
					<thead>
						<tr id="niv1">
		<?php
		$i = 1;
		foreach ($aEnteteTab as $iKey => $aEntete)
		{
			$sClass = "col".$i;
			if($aEntete['nom_colonne']=='Type') $sClass = "col2";
			if($aEntete['nom_colonne']=='Cotisation') $sClass = "col2";
			if($i==7) $sClass = "col6";
			if(($sEdition=='137') && ($aEntete['nom_colonne']== 'Date effet')) $sClass = "col3";
			if($aEntete['nom_colonne']== "Droit entr&eacute;e") $sClass = "col3";
			if($aEntete['nom_colonne']== "Fr&eacute;quence") $sClass = "col3";
			
		?>
						<td class='<?php echo $sClass ?>' style='text-align:center; height:25px; width:<?php echo ${'aPdfWidthRecord_'.$sEdition}[$aEntete['nom_colonne']]?>%; font-weight:bold;' >
		<?php echo $aEntete['nom_colonne']?>
						</td>
		<?php
			$i++;
		} ?>
						</tr>
					</thead>
					<tbody>
			
		<?php
			$aListes = array();
			switch ($sEdition)
			{
				case '135':
					$aListes=$oEditions->listeActesDeGestionAgent($aInfosAgent['Identifiant_agent'],$sDateDebut,$sDateFin);
					break;
					
				case '137':
					$aListes = $oEditions->listeSinistresDeclaresAgent($aInfosAgent['Identifiant_agent'],$sDateDebut,$sDateFin);
					break;

				case '138':
					$aListes=$oEditions->listeSinistresReglesAgent($aInfosAgent['Identifiant_agent'],$sDateDebut,$sDateFin);
					break;
				case '139':
						$aListes = $oEditions->listeSouscriptionsAgent($aInfosAgent['Identifiant_agent'],$sDateDebut,$sDateFin);
						break;
			}//fin switch
		
			$iTotalGeneral = $iMontPrest = 0;
		
			foreach ($aListes as $iKey => $aElement)
			{
				if(($iKey%2)==0) $sColorLine = ' class="colorligne" ';
				else $sColorLine = '';
		?>
					<tr id='niv2' <?php echo $sColorLine;?>>
						<td class='col1' align='center' style='height:25px;'><?php echo $aElement['Numero_contrat']?></td>
						<td class='col2' align='center' style='height:25px;'><?php echo formaterDate($aElement['Date_effet_contrat'])?></td>
						<td class='col3' align='center' style='height:25px;'><?php echo htmlentities($aElement['Libelle_offre'], ENT_COMPAT,'utf-8');?></td>
						<td class='col4' align='center' style='height:25px;'><?php echo htmlentities($aElement['Libelle_produit'], ENT_COMPAT,'utf-8');?></td>
						<td class='col5' align='center' style='height:25px;'><?php echo htmlentities($aElement['Libelle_formule'], ENT_COMPAT,'utf-8');?></td>

				<?php 
					if (isset($aElement['Montant_base_cotisation']))
					{
							// SOUSCRIPTIONS
							$fTotalCotisation += $aElement['Montant_base_cotisation']+$aElement['Montant_frais_echeance_cotisation'];
							$iNbContrat++;
							$fTotalDE += $aElement['Montant_droits_entree_cotisation'];
							$iTotalGeneral++;
				?>
						<td class='col1' align='center' style='height:25px;'><?php echo $aElement['Montant_base_cotisation']+$aElement['Montant_frais_echeance_cotisation']?></td>
						<td class='col7' align='center' style='height:25px;'><?php echo $aElement['Montant_droits_entree_cotisation']?></td>
				<?php 
					} 
				?>
						
				<?php 
					if (isset($aElement['Nom_element']))
					{ 
							// Actes de gestion
							if (!isset($aActe[$aElement['Nom_element']]))
							{
								$aActe[$aElement['Nom_element']] = 1;
							}
							else
							{
								$aActe[$aElement['Nom_element']]++;
							}
							$iTotalGeneral++;
				?>
						<td align='center' style='height:25px;'><?php echo $aElement['Nom_element']?></td>
				<?php 
					}
				?>
				<?php 
					if (isset($aElement['Frequence_paiement']))
					{ 
				?>
						<td class='col8' align='center' style='height:25px;'><?php echo $oElementDico->elementdico_getNomFromCode($aElement['Frequence_paiement'],'M0007') ?></td>
						<?php 
					} 
				?>
			
				<?php 
					if (isset($aElement['Type_sinistre']))
					{
							// SINISTRES
							?>
						<td align='center' style='height:25px;'><?php echo $oElementDico->elementdico_getNomFromCode($aElement['Type_sinistre'],'M0011')?></td>
						<td align='center' style='height:25px;'><?php echo formaterDate($aElement['Date_survenance_sinistre'])." &nbsp; ".formaterDate($aElement['Date_declaration_sinistre'])?></td>
				<?php 
					} 
				?>
			
				<?php 
					if (isset($aElement['Type_prestation']))
					{
							// SINISTRES REGLES
							if (!isset($aSinistreReg[$aElement['Type_sinistre']]))
							{
								$aSinistreReg[$aElement['Type_sinistre']] = 1;
							}
							else
							{
								$aSinistreReg[$aElement['Type_sinistre']]++;
							}
							
							if (!isset($aPrestation[$aElement['Type_sinistre']][$aElement['Type_prestation']]))
							{
								$aPrestation[$aElement['Type_sinistre']][$aElement['Type_prestation']] = $aElement['Montant_prestation'];
							}
							else
							{
								$aPrestation[$aElement['Type_sinistre']][$aElement['Type_prestation']] += $aElement['Montant_prestation'];
							}
							$iTotalGeneral++;
				?>
						<td align='center' style='height:25px;'><?php echo $oElementDico->elementdico_getNomFromCode('N'.$aElement['Type_prestation'], dataObject_dictionnaire::TYPE_PRESTATION)?></td>
						<td align='center' style='height:25px;'><?php echo $aElement['Montant_prestation']?></td>
						<td align='center' style='height:25px;'><?php echo formaterDate($aElement['Date_evenement'])?></td>
				<?php 
					} 
				?>
			
				<?php 
					if (isset($aElement['Etat_sinistre']))
					{
							// SINISTRES DECLARES
							if (!isset($aSinistreDec[$aElement['Type_sinistre']]))
							{
								$aSinistreDec[$aElement['Type_sinistre']] = 1;
							}
							else
							{
								$aSinistreDec[$aElement['Type_sinistre']]++;
							}
							$iTotalGeneral++;
							?>
						<td align='center' style='height:25px;'><?php echo $oElementDico->elementdico_getNomFromCode($aElement['Etat_sinistre'], dataObject_dictionnaire::_ETAT_SINISTRE)?></td>
						<td align='center' style='height:25px;'><?php echo $oElementDico->elementdico_getNomFromCode($aElement['Decision_partenaire_sinistre'], dataObject_dictionnaire::_TYPE_DECISION_ASSUREUR)?></td>
						<td align='center' style='height:25px;'><?php echo $oElementDico->elementdico_getNomFromCode($aElement['Motif_refus_sinistre'], dataObject_dictionnaire::MOTIF_REFUS_INDEMNISATION)?></td>
				<?php 
					} 
				?>
					</tr>
					<?php 
				} // fin foreach
				?>
					</tbody>
					<?php 		
				if (isset($aActe))
				{
					$sTotalAgent  = '';
					foreach ($aActe as $iKey => $sVal)
					{
							$sTotalAgent .= "
							<tr id='niv2'>
								<td class='col1' style='height:25px; width:30%;'>Agent ".$aInfosAgent['Nom_agent']."</td>
								<td class='col2' align='center' style='height:25px; width:35%;'>".$iKey."</td>
								<td class='col3' align='center' style='height:25px; width:35%;'>".$sVal."</td>
							</tr>";
					}
					if($sTotalAgent == '')
						$sTotalAgent = "
							<tr id='niv2'>
								<td class='col5' style='height:25px; width:30%;'>Agent ".$aInfosAgent['Nom_agent']."</td>
								<td class='col2' align='center' style='height:25px; width:35%;'>-</td>
								<td class='col3' align='center' style='height:25px; width:35%;'>0</td>
							</tr>";
				
					echo $sSepareTable.$sTabActe.$sTotalAgent.'</table>';
				}
				else if (isset($aSinistreDec))
				{
						$sTotalAgent = '';
						foreach ($aSinistreDec as $iKey => $sVal)
						{
							$sTotalAgent .= "
							<tr id='niv2'>
								<td  class='col1' style='height:25px; width:34%;' >Agent ".$aInfosAgent['Nom_agent']."</td>
								<td  class='col2' align='center' style='height:25px; width:33%;'>".$oElementDico->elementdico_getNomFromCode($iKey, dataObject_dictionnaire::TYPE_SINISTRE)."</td>
								<td  class='col3' align='center' style='height:25px; width:33%;'>".$sVal."</td>
							</tr>";
							
						}
						if($sTotalAgent == '')
							$sTotalAgent = "
							<tr id='niv2'>
								<td  class='col1' style='height:25px; width:34%;'>Agent ".$aInfosAgent['Nom_agent']."</td>
								<td  class='col2' align='center' style='height:25px; width:33%;'>-</td>
								<td  class='col3' align='center' style='height:25px; width:33%;'>0</td>
							</tr>";
			
						echo $sSepareTable.$sTabSinistreDec.$sTotalAgent.'</table>';
				}
				else if (isset($aSinistreReg))
				{
						$sTotalAgent = '';
						foreach ($aSinistreReg as $iKey => $sVal)
						{
							foreach ($aPrestation[$iKey] as $iKey1 => $sVal1)
							{
									$sTotalAgent .= "
									<tr id=\"niv2\">
										<td class='col1'>Agent ".$aInfosAgent['Nom_agent']."</td>
										<td class='col2 align='center''>".$oElementDico->elementdico_getNomFromCode($iKey, dataObject_dictionnaire::TYPE_SINISTRE)."</td>
										<td class='col2' align='center'>".$sVal."</td>
										<td class='col2' align='center'>".$oElementDico->elementdico_getNomFromCode('N'.$iKey1, dataObject_dictionnaire::TYPE_PRESTATION)."</td>
										<td class='col2' align='center'>".$sVal1."</td>
									</tr>";
									$iMontPrest += $sVal1;
							}
						}
						if($sTotalAgent == '')
							$sTotalAgent = "
							<tr id='niv2'>
								<td class='col1'>Agent ".$aInfosAgent['Nom_agent']."</td>
								<td class='col2' align='center'>-</td>
								<td class='col2' align='center'>0</td>
								<td class='col2' align='center'>-</td>
								<td class='col2' align='center'>0</td>
							</tr>";
						echo $sSepareTable.$sTabSinistreReg.$sTotalAgent.'</table>';
				}
				else
				{
						$sTotalAgent .= "
						<tr id='niv2'>
						<td  class='col3'> Agent ".$aInfosAgent['Nom_agent']."</td>
						<td  class='col3' align='center'>".$iNbContrat."</td>
						<td  class='col3' align='center'>".$fTotalCotisation."</td>
						<td  class='col6' align='center'>".$fTotalDE."</td>
						</tr>";
	
						echo $sSepareTable.$sTabSous.$sTotalAgent.'</table>';
						
				}
			?>
		
					
				
				</div> <!-- fin content_table -->
				<?php
				}
				?>
				</PDF>    
			</div>
			
			<div class="imgright1"></div>			
			<div class="cleared"></div> 
			<?php

	$sHtml = ob_get_contents();
	//$sNomListe = utf8_decode($sNomListe);
	$sNomfichier = preg_replace('/&eacute;/','e',$sNomListe);
	$sNomfichier = preg_replace('/&egrave;/','e',$sNomfichier);
	$sNomfichier = preg_replace('/&#130;/','_',$sNomfichier);
	$sNomfichier = str_replace("d'",'',$sNomfichier);
	$sNomfichier = str_replace("é",'e',$sNomfichier);
	$oFichierPDF = new CHMTL_PDF($sHtml, $sNomfichier,'L',false, false);
	$sUrlPrint = "succes_impression.php?file=".$oFichierPDF->sFileEdition;
	?>
			<form action="<?php echo $sEditFormAction ?>" method="post" name="form1" id="form1" class="formulaire">
				<input type="hidden" name="nomListe" maxlength="50" class="resizeall" value="<?php echo $sNomListe ?>" size="32" />
				<table>
					<tr>
						<td align="center">ADRESSE MAIL</td>
						<td ><input type="text" name="OEM_email" maxlength="50" class="resizeall" value="" size="32" /></td>
					</tr>
				</table>
			
				<input type="hidden" name="file" value="<?php echo $oFichierPDF->sEdition; ?>" />
				<input type="hidden" name="deb" value="<?php echo formaterDate($sDateDebut,"-","/",false); ?>" />
				<input type="hidden" name="fin" value="<?php echo formaterDate($sDateFin,"-","/",false); ?>" />
				
				<div class="bt1">
					<span class="btleft"></span> <a href="../editions"> 
					<input type="submit" name="Retour" value="Retour" class="resizeall btmiddle" />
					<span class="btright"></span> </a>
				</div>
				<div class="bt1">
					<span class="btleft"></span> 
					<input type="submit" name="Envoyer" value="Envoyer par mail" class="resizeall btmiddle" /> 
					<span class="btright"></span>
				</div>
			</form>
			<div class="bt1">
				<span class="btleft"></span> 
				<input type="submit" name="Imprimer" value="Imprimer" class="resizeall btmiddle" onclick="javascript:printEdition('<?php echo $sUrlPrint ?>');" />
				<span class="btright"></span>
			</div>
			
			<!--/***************************************/-->
		</div>
	</body>
</html>
	
		<?php
		include_once PATH_INCLUDE.'inc_pied_page.php';

/**
 * fonction qui permet de changer le format d'une date 
 * 
 * @param  string $sDate date à formater : au format "JJ-MM-AAAA", "JJ/MM/AAAA", "AAAA-MM-JJ" ou "AAAA/MM/JJ"
 * @param  char $sSeparateur sépareteur de la date à formater : vaut "-" ou "/"
 * @param  char $NouveauSeparateur sépareteur de la date formater (resultat) : vaut "-" ou "/"
 * @param  bool $bInverser : vaut true si on veut inveser le format de la date etré en parametre et false sinon
 * @return string : au format "JJ-MM-AAAA", "JJ/MM/AAAA", "AAAA-MM-JJ" ou "AAAA/MM/JJ"
 */
function formaterDate($sDate, $sSeparateur = "-", $NouveauSeparateur = "-", $bInverser = true)
{
	$aTab = explode($sSeparateur, $sDate);
	
	if ($bInverser)
		$sRetour = $aTab[2].$NouveauSeparateur.$aTab[1].$NouveauSeparateur.$aTab[0];
	else
		$sRetour = $aTab[0].$NouveauSeparateur.$aTab[1].$NouveauSeparateur.$aTab[2];
	
	return $sRetour;
}
		?>